<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); 

class Common {
	
	static public function _better_sha1_token() {
		$better_token = sha1(uniqid(mt_rand(), TRUE));
		return $better_token;
	}
	
	static public function _sha1_add_salt($data, $salt = COOKIE_SALT) {
		$added_salt_data = sha1($salt . sha1($data . $salt));
		return $added_salt_data;
	}
	
	static public function filter_chs($str) {
		$par = "/[\x80-\xff]/";
		return preg_replace($par,"",$str);
	}
	
	function _is_admin() {
		if (isset($_SESSION['ucid']) && $_SESSION['ucid'] == ADMIN_UCID) {
			return TRUE;
		} else {
			return FALSE;
		}
	}
	
	function _get_array_nearest($array, $cur_val) {
		$cur_key = array_search($cur_val, $array);
		$prev_key = $cur_key - 1;
		$next_key = $cur_key + 1;
		
		if (array_key_exists($prev_key, $array)) {
			$nearest['prev'] = $array[$prev_key];
		}
		if (array_key_exists($next_key, $array)) {
			$nearest['next'] = $array[$next_key];
		}
		return (isset($nearest)) ? $nearest : '';
	}
}

?>